#include <iostream>
using namespace std;

//虚析够函数
class A
{
private:
        char  *a;
public: 
        A(){
                a = new char[10];
                cout<<"A的构造方法"<<endl;
        }
        virtual ~A(){
                delete [] a;
                cout<<"A的析够方法"<<endl;
        }
};

class B : public A
{
private:
        char  *b;
public: 
        B(){
                b = new char[10];
                cout<<"B的构造方法"<<endl;
        }
        ~B(){
                delete [] b;
                cout<<"B的析够方法"<<endl;
        }
};

class C : public B
{
private:
        char  *c;
public: 
        C(){
                c = new char[10];
                cout<<"C的构造方法"<<endl;
        }
        ~C(){
                delete [] c;
                cout<<"C的析够方法"<<endl;
        }
};

//只执行了 父类的析够函数 会出现内存泄漏
//问 通过父类指针 把 所有的子类对象的析够函数 都执行一片
//问 通过父类指针 释放所有的子类资源
//需要通过父类虚析够函数才能满足
void howtodelete(A *base){
        delete base; //这句话不会表现成多态 这种属性
}

int main(int argc, char const *argv[])
{
        C  *myc = new C;
        //delete myc; //直接通过子类释放 不需要写virtual
        howtodelete(myc);
        return 0;
}